<template>
	<div>
		<el-dialog :visible.sync="dialogVisible" :show-close="false">
			<div slot="title"
				style="border-bottom: 1px solid #cbcbcb;display: flex;align-items: center;justify-content: space-between;padding-bottom: 15px;">
				<div style="font-size: 18px;color: #333;">需求详情</div>
				<i class="el-icon-close" style="cursor: pointer;" @click="close()"></i>
			</div>

			<div>
				<div class="el-form-item__label">申请信息</div>
				<el-descriptions class="margin-top" title="" :column="2" border>
					<el-descriptions-item>
						<template slot="label">
							需求标题
						</template>
						{{info.title}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							姓名
						</template>
						{{info.userName}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							职务
						</template>
						{{info.dept}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							联系电话
						</template>
						{{info.phone}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							需求描述
						</template>
						{{info.description}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							产品形式
						</template>
						{{info.productForm}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							所属业务类别
						</template>
						{{info.categoryName}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							需求发布时间
						</template>
						{{updateTimeChange(info.createTime)}}
					</el-descriptions-item>
					<el-descriptions-item>
						<template slot="label">
							需求有效期
						</template>
						{{updateTimeChange(info.effectiveTime)}}
					</el-descriptions-item>
				</el-descriptions>

			</div>

			<div slot="footer" style="display: flex;justify-content: center;">
				
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		postMyDemandAudit
	} from "@/request/api/demand";
	export default {
		data() {
			return {
				dialogVisible: false,
				info: {},

				form: {
					"id": '', // 需求ID
					"status": '', // 审批状态，1未审批，2审批通过，3驳回
					"comment": "" // 审核意见
				},
				rules: {
					status: [{
						required: true,
						message: '请选择',
						trigger: 'blur'
					}, ],
				},
			};
		},
		methods: {
			open(info) {
				this.dialogVisible = true
				this.info = info
				this.form = {
					"id": '', // 需求ID
					"status": '', // 审批状态，1未审批，2审批通过，3驳回
					"comment": "" // 审核意见
				}
				this.form.id = info.id
			},
			// 格式化时间
			updateTimeChange(val) {
				return this.$moment(val).format('YYYY-MM-DD')
			},

			// 关闭
			close() {
				this.dialogVisible = false
			},
			// 创建
			submitForm(val) {
				this.$refs.form.validate((valid) => {
					if (valid) {
						if(this.form.status==2){
							this.getAdd(this.form);
						}else if(this.form.status==3){
							this.getAdd(this.form);
						}
					} else {
						return false;
					}
				});
			},
			// 修改接口
			getAdd(params) {
				postMyDemandAudit(params).then((res) => {
					if (res.data.code === 1) {
						this.$message({
							message: res.data.message,
							type: "success",
						});
						this.$emit('getNewList')
						this.dialogVisible = false
					} else {
						this.$message.error(res.data.message);
					}
				});
			},
		}
	}
</script>

<style lang="less" scoped>
	/* 适用于手机的样式 */
	@media (max-width: 767px) {
		/deep/.el-dialog {
			width: 95%;
		}
	}

	.form-label {
		margin-top: 10px;
		text-align: right;
		padding-right: 15px;
	}
</style>